//
//  MyAwardController.m
//  DianDangDai
//
//  Created by bhf on 2017/12/18.
//  Copyright © 2017年 bhf. All rights reserved.
//

#import "MyAwardController.h"
#import "AlertViewTopView.h"
#import <Photos/Photos.h>
#import "AttributedIntString.h"
@interface MyAwardController ()
@property (nonatomic ,assign) BOOL leftOrRight;
@end

@implementation MyAwardController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:NO];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupViews];
    
    // Do any additional setup after loading the view.
}

- (void)setupViews {
    self.title = @"邀请奖励";
    _code.layer.cornerRadius = 4;
    _share.layer.cornerRadius = 4;
    _contentView.layer.cornerRadius = 10;
    AttributedIntString *string = [[AttributedIntString alloc] init];
    self.price.attributedText = [string attributedStringWithString:@"200元" setTextColor:[UIColor colorWithHex:@"#ff2600"]];
}
- (IBAction)changeData:(UIButton *)sender {
    
    if (_leftOrRight) {
        _jiangli.text = @"直接奖励";
        _line.frame = CGRectMake(0, _line.y, _line.width, _line.height);
        [sender setTitleColor:THE_MASS_TONE_ATTUNE forState:UIControlStateNormal];
        [_rightBtn setTitleColor:[UIColor colorWithHex:@"#333333"] forState:UIControlStateNormal];
        _leftOrRight = NO;
    } else if (!_leftOrRight) {
        _jiangli.text = @"间邀奖励";
        _line.frame = CGRectMake(_line.width, _line.y, _line.width, _line.height);
        [sender setTitleColor:THE_MASS_TONE_ATTUNE forState:UIControlStateNormal];
        [_leftBtn setTitleColor:[UIColor colorWithHex:@"#333333"] forState:UIControlStateNormal];
        _leftOrRight = YES;
    }
}
- (IBAction)InvitationCode:(UIButton *)sender {
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"\n\n\n\n\n\n\n\n\n\n" message:nil preferredStyle:UIAlertControllerStyleAlert];
    AlertViewTopView *view = [[AlertViewTopView alloc] init];
    view.frame = CGRectMake(0, 0, 270, 262);
    [alert.view addSubview:view];
    
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"保存二维码" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self loadImageFinished:view.imageView.image];
    }];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alert addAction:action];
    [alert addAction:cancel];
    [self presentViewController:alert animated:NO completion:nil];
    
}

- (void)loadImageFinished:(UIImage *)image
{
    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
        
        //写入图片到相册
        PHAssetChangeRequest *req = [PHAssetChangeRequest creationRequestForAssetFromImage:image];
        
        
    } completionHandler:^(BOOL success, NSError * _Nullable error) {
        
        NSLog(@"success = %d, error = %@", success, error);
        
    }];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
